package com.yungu.swift.admin.route.finance;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.utils.ExcelUtil;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.system.finance.model.param.AdminRefundPageParam;
import com.yungu.swift.system.finance.model.vo.FinanceRefundVo;
import com.yungu.swift.system.finance.service.FinanceRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : cuixiuyin
 * @date : 2019/8/27
 */
@RestController
@RequestMapping("/admin/v1/finance/refund/bill")
@Api(value = "【财务管理】", tags = "退款账单")
public class RefundBillAdmin {

    @Reference
    private FinanceRefundService financeRefundService;

    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "退款账单分页查询", httpMethod = "POST")
    public ResponseData<PageVo<FinanceRefundVo>> queryPage(@RequestBody AdminRefundPageParam refundPageParam) {
        return financeRefundService.queryPageVo(refundPageParam);
    }

    @RequestMapping("/export")
    @ApiOperation(value = "退款账单导出", httpMethod = "POST")
    public void export(@RequestBody AdminRefundPageParam refundPageParam, HttpServletResponse response) {
        List<FinanceRefundVo> list = financeRefundService.export(refundPageParam).getData();
        Map<Object, Object>[] dictionaryMapArray = new Map[11];
        //退款账户字典
        dictionaryMapArray[7] = new HashMap<>(4);
        dictionaryMapArray[7].put(1, "微信");
        dictionaryMapArray[7].put(2, "支付宝");
        dictionaryMapArray[7].put(4, "余额");

        //退款状态字典
        dictionaryMapArray[10] = new HashMap<>(4);
        dictionaryMapArray[10].put(1, "退款中");
        dictionaryMapArray[10].put(2, "退款成功");
        dictionaryMapArray[10].put(3, "退款失败");
        ExcelUtil.export(response, "退款账单", list, 11,
                new String[]{"退款提交时间", "退款完成时间", "订单号", "原平台流水", "退款平台流水", "退款人昵称",
                        "退款人手机号", "退款账户", "退款类型", "退款金额（元）", "退款状态"},
                new String[]{"createOn", "updateOn", "orderNo", "sfoFinanceNumber", "financeNumber", "nickname",
                        "mobile", "type", "courseDescription", "amount", "status"},
                dictionaryMapArray);
    }
}
